﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using UnityEngine;

public class SystemSender
{
    private static SystemSender self;

    public SystemSender() { }

    public static SystemSender getInstance()
    {
        if (self == null)
        {
            self = new SystemSender();
        }
        return self;
    }

    /// <summary>
    /// 选择场景中对象（可扩展，针对场景对象的类型）
    /// </summary>
    public void SelectObjInScene(Point objKey)
    {
        //ByteArrayEx sendArr = new ByteArrayEx();

        ByteArrayEx arrPlist = new ByteArrayEx();
        arrPlist.writeInt(SystemMsgFlag.CLIENT_SELECT);
        arrPlist.writeObject(objKey);
        //sendArr.writeInt(arrPlist.length);
        //sendArr.writeBytes(arrPlist.byteArray);

        MySocket.getInstance().Async_Send(arrPlist.byteArray);

        Debug.Log("发送自定义消息-->选择场景对象");
    }


    /// <summary>
    /// 消息格式：totalLength + (messageType + (type+data)...)
    /// </summary>
    public void CustomMsgEx(int type, params object[] pList)
    {
        //ByteArrayEx sendArr = new ByteArrayEx();
       
        ByteArrayEx arrPlist = new ByteArrayEx();
        arrPlist.writeInt(SystemMsgFlag.SERVER_CUSTOM);
        foreach(object val in pList)
        {
            arrPlist.WriteData(val);
        }
        //sendArr.writeInt(arrPlist.length);
        //sendArr.writeBytes(arrPlist.byteArray);

        MySocket.getInstance().Async_Send(arrPlist.byteArray);

        Debug.Log("发送自定义消息-->类型："+ type +"长度："+arrPlist.length);


    }

}
